package com.xianyun.rpc.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.dialect.Props;

/**
 * @author xianYun
 * @version 1.0
 **/
public class ConfigUtils {
    public static <T> T loadConfig(Class<T> tClass,String prefix){
        T loadConfig = loadConfig(tClass, prefix, "");
        return loadConfig;
    }

    public static <T> T loadConfig(Class<T> tClass,String prefix,String environment){
        //单线程环境下，使用 StringBuilder 拼接字符串的效率高。
        StringBuilder configFileName = new StringBuilder("application");
        if (StrUtil.isNotBlank(environment)){
            configFileName.append("-").append(environment);
        }
        configFileName.append(".properties");
        Props props = new Props(configFileName.toString());
        return props.toBean(tClass,prefix);
    }
}
